package com.onpositive.wiki3.db.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

import com.carrotsearch.hppc.IntOpenHashSet;

public class PageVocubalary {

	HashMap<String, IntOpenHashSet> words = new HashMap<String, IntOpenHashSet>();

	void add(String d,int page) {
		IntOpenHashSet integer = words.get(d);
		if (integer == null) {
			integer = new IntOpenHashSet();
			words.put(d, integer);
		}
		integer.add(page);
	}

	static class Pair implements Comparable<Pair> {
		String s;
		int i;

		public Pair(String s2, Integer integer) {
			this.s = s2;
			this.i = integer;
		}

		@Override
		public int compareTo(Pair o) {
			return -this.i + o.i;
		}

		public String toString() {
			return s + ":" + i;
		}
	}

	public ArrayList<Pair> all() {
		ArrayList<Pair> ps = new ArrayList<PageVocubalary.Pair>();
		for (String s : words.keySet()) {
			Pair p = new Pair(s, words.get(s).size());
			ps.add(p);
		}
		Collections.sort(ps);
		return ps;
	}

	public IntOpenHashSet get(String title) {
		return words.get(title);
	}

	public void add(String title, IntOpenHashSet int0) {
		if (title.equals("Hidden_categories")){
			return;
		}
		if (title.equals("Stub_categories")){
			return;
		}
		if (title.equals("Wikipedia_maintenance")){
			return;
		}
		if (title.equals("Wikipedia_backlog")){
			return;
		}
		if (title.equals("Container_categories")){
			return;
		}
		
		
		
		IntOpenHashSet integer = words.get(title);
		if (integer == null) {
			integer = new IntOpenHashSet();
			words.put(title, integer);
		}
		
		integer.addAll(int0);
		
	}
}
